<template>
    <div class="goods-item" @click="itemClick">
        <img v-lazy="product.cover_url" alt="">
        <div class="goods-info">
            <p class="goods-title">{{ product.title }}</p>
            <span class="goods-price"><small>￥</small>{{ product.price }}</span>
            <span class="collect"><span class="iconfont icon-shoucang"></span>{{ product.collects_count }}</span>
        </div>
    </div>
</template>

<script>

import {useRouter} from 'vue-router';

export default {
    name: "GoodsListItem",
    props: {
        product: {
            type: Object,
            default() {
                return {}
            }
        }
    },
    setup(props) {
        const router = useRouter();
        
        return {
            itemClick: () => {
                router.push({path: '/detail', query: {id: props.product.id}})
            }
        }
    }
}
</script>

<style scoped lang="scss">
    .goods-item {
        position: relative;
        width: 46%;
        height: 220px;
        margin-bottom: 15px;
        img {
            width: 100%;
            height: 173px;
            border-radius: 8px;
        }
        .goods-info {
            position: absolute;
            font-size: 12px;
            left: 0;
            right: 0;
            .goods-title {
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
                margin: 8px 0 5px;
            }
        }
        .goods-price {
            color: red;
        }
        .collect {
            font-size: 12px;
            .iconfont {
                font-size: 12px;
                padding: 0 5px;
            }
        }
    }
</style>